##################################################################
# File : /lua/ui/network/dataserver.lua
# Description : Dark Skies networking module
# Author : Neruz
##################################################################

local internalComm = import('/lua/ui/network/lobbycomm.lua')

DataServer = Class(internalComm.LobbyComm) {
	DataReceived = function(self, data)
		local _type = data._type
		local senderId = data.SenderID
		local senderName = data.SenderName
		#LOG('server', repr(data))
		if _type == "CheckVersion" then
			local version = data.version
			self:SendData(senderId, {_type = 'VersionInfo', version = __DSVERSION__})
		elseif _type == "RequestAnnouncements" then
			local announcements = {{time = '13/12/08', title = 'Test announcement', description = 'Hello there'}, {time = '13/12/08', title = 'Server is up or something', description = 'Yeah.'}}
			self:SendData(senderId, {_type = 'Announcements', announcements = announcements})
		end
	end,
}

function InitDataServer(protocol, port)
    local comm = DataServer(protocol, port, internalComm.maxConnections, "dataServer", nil, nil)
    return comm
end